Process Analysis Toolkit (PAT) 3.5 Help |
Some complicated calculations (e.g., algorithms, data
operations and computations) are difficult to implement in PAT's modeling
language. Beside supporting calling C# methods, we also allow users to call
C/C++ functions in PAT. Suppose you have a C/C++ library, all you need is to create
a C# interface using that library and then call C# interface as External Static
Method.Requirements to the C# external static
methods are also applied to the C/C++ functions. Example: You have a C function in the Plus.dll which return the sum
of 2 integer numbers For more information about how to export a C function, you
may want to refer to Exporting from a DLL Using __declspec(dllexport). The basic
idea is adding "extern "C" __declspec( dllexport )" before the interface
declaration to mark it as be exported to the DLL. You want to call this function in PAT. Firstly, you need to
create an C# interface provoking this function. You may want to try as
below: public class CMethodDemo { [DllImport(@"Lib\Plus.dll")] public static extern int plus(int a, int b); } To call a DLL from C#, we need to declare a method as having
an implementation from that DLL with the static and
extern C# keywords. Then you need to attach the DllImport
attribute to the method. For deeper understanding, following the tutorial
Platform Invoke Tutorial from MSDN. Then you build this as CMethodDemo.dll, put it and Plus.dll
under "Lib" folder of the PAT installation directory. Last you can follow the
External
Static Methods to use this C# interface. Below is
the PAT model using this feature. You can try this example in PAT, under
CSP -> "Demonstrating Example" -> "C Library Demonstrating
Example". #
extern "C" __declspec( dllexport ) plus(int a, int b);
var
x;System = event{x = call(plus, 1,2);} -> out.x -> Skip;
#
assert System() deadlockfree;